package com.example.util;


import sun.awt.SunHints;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.InputStream;

/**
 * @program: ms
 * @description: 生成图片
 * @author: Mr.Wang
 * @create: 2020-01-08 10:47
 **/
public class ImageBuilderUtils {
    /**
     */
    private static final int width = 283;
    //private static final int width = 350;
    /**
     */
    private static final int height = 375;
   // private static final int height = 500;




    public static String ImageBuilder(InputStream qrFileInputStream, InputStream headPhotoFileInputStream, InputStream backgroundFileInputStream) {


        //得到图片缓冲区
        try {
            BufferedImage bgImage = ImageIO.read(backgroundFileInputStream); //背景图片

            BufferedImage qrImage = ImageIO.read(qrFileInputStream); //二维码图片
            BufferedImage hpImage = ImageIO.read(headPhotoFileInputStream); //头像图片
            //得到它的绘制环境(这张图片的笔)
            Graphics2D g2 = (Graphics2D) bgImage.getGraphics();

            int width = bgImage.getWidth();
            int hp = width - 80;
            int qr = width - 120;
            //g2.drawImage(bgImage, 0, -10, 283, 375,null);
            g2.drawImage(hpImage, hp/2, 150, 80, 80,null);
            g2.drawImage(qrImage, qr/2, 450, 120, 120,null);


            g2.setFont(new Font("苹方", Font.BOLD, 20));
            g2.setColor(Color.WHITE);
            int strWidth = g2.getFontMetrics().stringWidth("小情绪大师傅但是");
            int strW =  width - strWidth;
            g2.drawString("小情绪大师傅但是", strW / 2, 270);

            g2.dispose();

            String savePath = "D:/final.png";
            ImageIO.write(bgImage, "png", new FileOutputStream(savePath));
            return savePath;
        }catch (Exception e){
            System.out.println("生成图片错误");
            return null;
        }
    }

    public static void main(String[] args) {
        String s = "\n" +
                "m-mall-agent_2020-09-30.7.log:2020-09-30 10:59:27,907 INFO [http-nio-8022-exec-165] RequestLogAdvice [TID:d13f58d27dbd4f72ab52d17df3a1c54f.3240.16014347678856493] [RequestLogAdvice.java:72] -----------POST-------------request[/v1/app/cloudstock/exchange/item]--start--[request params：{exchangeGoods=ExchangeGoods(list=[ExchangeItemAndNum(itemId=1128202293977153536, skuCode=C045-H, amount=2, type=1), ExchangeItemAndNum(itemId=1178144813704708096, skuCode=C046-H, amount=2, type=1), ExchangeItemAndNum(itemId=1294093332657999872, skuCode=30390010, amount=2, type=1), ExchangeItemAndNum(itemId=1310472197861027840, skuCode=30410010, amount=2, type=0)], mallUserId=null, memo=, optionType=null, optionId=null)}";

        int i = s.indexOf("TID:");
        int y = s.indexOf("TID:");
    }
}
